#include "fillers.h"
#include "nodrop.h"

#include "events.h"

#define FILLER_REF(x) f_##x, NOD_FILLER_##x

#define f_sys_socket_x f_sys_single_x

const struct nod_event_entry g_nod_events[NODE_EVENT_MAX] = {
	[NODE_GENERIC] = {FILLER_REF(sys_generic)},
	[NODE_SYSCALL_OPEN] = {FILLER_REF(sys_open)},
	[NODE_SYSCALL_CLOSE] = {FILLER_REF(sys_empty), 2, APT_SOCK, {{0}, {AF_ID_RETVAL}}},
	[NODE_SYSCALL_READ] = {FILLER_REF(sys_read), 2, APT_REG, {{0}, {2}}},
	[NODE_SYSCALL_WRITE] = {FILLER_REF(sys_write), 2, APT_REG, {{0}, {2}}},
	[NODE_SYSCALL_BRK_1] = {FILLER_REF(sys_empty), 2, APT_REG, {{0}, {AF_ID_RETVAL}}},
	[NODE_SYSCALL_EXIT] = {FILLER_REF(sys_empty), 1, APT_REG, {{0}}},
	[NODE_SYSCALL_EXIT_GROUP] = {FILLER_REF(sys_empty), 1, APT_REG, {{0}}},
	[NODE_SYSCALL_EXECVE_8] = {FILLER_REF(sys_execve)},
	[NODE_SYSCALL_CLONE_11] = {FILLER_REF(sys_procstart)},
	[NODE_SOCKET_SOCKET] = {FILLER_REF(sys_empty), 4, APT_SOCK, {{0}, {1}, {2}, {AF_ID_RETVAL}}},
	[NODE_SOCKET_BIND] = {FILLER_REF(sys_socket_bind), 1, APT_SOCK, {{0}}},
	[NODE_SOCKET_CONNECT] = {FILLER_REF(sys_connect), 1, APT_SOCK, {{0}}},
	[NODE_SOCKET_LISTEN] = {FILLER_REF(sys_empty), 3, APT_SOCK, {{0}, {1}, {AF_ID_RETVAL}}},
	[NODE_SOCKET_SEND] = {FILLER_REF(sys_send)},
	[NODE_SOCKET_SENDTO] = {FILLER_REF(sys_sendto)},
	[NODE_SOCKET_RECV] = {FILLER_REF(sys_recv), 2, APT_SOCK, {{0}, {2}}},
	[NODE_SOCKET_RECVFROM] = {FILLER_REF(sys_recvfrom), 2, APT_SOCK, {{0}, {2}}},
	[NODE_SOCKET_SHUTDOWN] = {FILLER_REF(sys_shutdown), 1, APT_REG, {{AF_ID_RETVAL}}},
	[NODE_SOCKET_GETSOCKNAME] = {FILLER_REF(sys_empty)},
	[NODE_SOCKET_GETPEERNAME] = {FILLER_REF(sys_empty)},
	[NODE_SOCKET_SOCKETPAIR] = {FILLER_REF(sys_socketpair), 3, APT_SOCK, {{0}, {1}, {2}}},
	[NODE_SOCKET_SETSOCKOPT] = {FILLER_REF(sys_setsockopt)},
	[NODE_SOCKET_GETSOCKOPT] = {FILLER_REF(sys_getsockopt)},
	[NODE_SOCKET_SENDMSG] = {FILLER_REF(sys_sendmsg)},
	[NODE_SOCKET_SENDMMSG] = {FILLER_REF(sys_empty)},
	[NODE_SOCKET_RECVMSG] = {FILLER_REF(sys_recvmsg), 1, APT_SOCK, {{0}}},
	[NODE_SOCKET_RECVMMSG] = {FILLER_REF(sys_empty)},
	[NODE_SYSCALL_CREAT] = {FILLER_REF(sys_creat)},
	[NODE_SYSCALL_PIPE] = {FILLER_REF(sys_pipe)},
	[NODE_SYSCALL_EVENTFD] = {FILLER_REF(sys_eventfd), 1, APT_REG, {{AF_ID_RETVAL}}},
	[NODE_SYSCALL_FUTEX] = {FILLER_REF(sys_futex), 1, APT_REG, {{AF_ID_RETVAL}}},
	[NODE_SYSCALL_STAT] = {FILLER_REF(sys_empty), 2, APT_REG, {{AF_ID_RETVAL}, {0}}},
	[NODE_SYSCALL_LSTAT] = {FILLER_REF(sys_empty), 2, APT_REG, {{AF_ID_RETVAL}, {0}}},
	[NODE_SYSCALL_FSTAT] = {FILLER_REF(sys_empty), 2, APT_REG , {{AF_ID_RETVAL}, {0}}},
	[NODE_SYSCALL_STAT64] = {FILLER_REF(sys_empty), 2, APT_REG, {{AF_ID_RETVAL}, {0}}},
	[NODE_SYSCALL_LSTAT64] = {FILLER_REF(sys_empty), 2, APT_REG, {{AF_ID_RETVAL}, {0}}},
	[NODE_SYSCALL_FSTAT64] = {FILLER_REF(sys_empty), 2, APT_REG, {{0}, {AF_ID_RETVAL}}},
	[NODE_SYSCALL_EPOLLWAIT] = {FILLER_REF(sys_empty), 2, APT_REG, {{2}, {AF_ID_RETVAL}}},
	[NODE_SYSCALL_POLL] = {FILLER_REF(sys_poll)},
	[NODE_SYSCALL_SELECT] = {FILLER_REF(sys_empty), 1, APT_REG, {{AF_ID_RETVAL}}},
	[NODE_SYSCALL_LSEEK] = {FILLER_REF(sys_lseek), 1, APT_REG, {{AF_ID_RETVAL}}},
	[NODE_SYSCALL_LLSEEK] = {FILLER_REF(sys_llseek), 1, APT_REG, {{AF_ID_RETVAL}}},
	[NODE_SYSCALL_GETCWD] = {FILLER_REF(sys_empty), 2, APT_REG, {{AF_ID_RETVAL}, {0}}},
	[NODE_SYSCALL_CHDIR] = {FILLER_REF(sys_empty), 2, APT_REG, {{AF_ID_RETVAL}, {0}}},
	[NODE_SYSCALL_FCHDIR] = {FILLER_REF(sys_empty), 2, APT_REG, {{0}, {AF_ID_RETVAL}}},
	[NODE_SYSCALL_UNLINK] = {FILLER_REF(sys_empty), 2, APT_REG, {{0}, {AF_ID_RETVAL}}},
	[NODE_SYSCALL_UNLINKAT] = {FILLER_REF(sys_empty), 3, APT_REG, {{0}, {1}, {AF_ID_RETVAL}}},
#ifdef _64BIT_ARGS_SINGLE_REGISTER
	[NODE_SYSCALL_PREAD] = {FILLER_REF(sys_read), 3, APT_REG, {{0}, {2}, {3}}},
	[NODE_SYSCALL_PWRITE] = {FILLER_REF(sys_write), 3, APT_REG, {{0}, {2}, {3}}},
#else
	[NODE_SYSCALL_PREAD] = {FILLER_REF(sys_pread)}, // _X: +sys_read
	[NODE_SYSCALL_PWRITE] = {FILLER_REF(sys_pwrite)}, // _X: +sys_write
#endif // _64BIT_ARGS_SINGLE_REGISTER
	[NODE_SYSCALL_READV] = {FILLER_REF(sys_readv_preadv), 1, APT_REG, {{0}}},
	[NODE_SYSCALL_WRITEV] = {FILLER_REF(sys_writev)},
#ifdef _64BIT_ARGS_SINGLE_REGISTER
	[NODE_SYSCALL_PREADV] = {FILLER_REF(sys_readv_preadv), 2, APT_REG, {{0}, {3}}},
#else
	[NODE_SYSCALL_PREADV] = {FILLER_REF(sys_preadv)}, // _X: +sys_readv_preadv
#endif //_64BIT_ARGS_SINGLE_REGISTER
	[NODE_SYSCALL_PWRITEV] = {FILLER_REF(sys_pwritev)},
	[NODE_SYSCALL_DUP] = {FILLER_REF(sys_empty), 2, APT_REG, {{0}, {AF_ID_RETVAL}}},
	[NODE_SYSCALL_SIGNALFD] = {FILLER_REF(sys_empty), 4, APT_REG, {{0}, {AF_ID_USEDEFAULT, 0}, {AF_ID_USEDEFAULT, 0}}},
	[NODE_SYSCALL_KILL] = {FILLER_REF(sys_empty), 3, APT_REG, {{0}, {1}, {AF_ID_RETVAL}}},
	[NODE_SYSCALL_TKILL] = {FILLER_REF(sys_empty), 3, APT_REG, {{0}, {1}, {AF_ID_RETVAL}}},
	[NODE_SYSCALL_TGKILL] = {FILLER_REF(sys_empty), 4, APT_REG, {{0}, {1}, {2}, {AF_ID_RETVAL}}},
	[NODE_SYSCALL_NANOSLEEP] = {FILLER_REF(sys_nanosleep), 1, APT_REG, {{AF_ID_RETVAL}}},
	[NODE_SYSCALL_TIMERFD_CREATE] = {FILLER_REF(sys_empty), 3, APT_REG, {{AF_ID_USEDEFAULT, 0}, {AF_ID_USEDEFAULT, 0}, {AF_ID_RETVAL}}},
	[NODE_SYSCALL_INOTIFY_INIT] = {FILLER_REF(sys_empty), 2, APT_REG, {{AF_ID_USEDEFAULT, 0}, {AF_ID_RETVAL}}},
	[NODE_SYSCALL_GETRLIMIT] = {FILLER_REF(sys_getrlimit_setrlrimit)},
	[NODE_SYSCALL_SETRLIMIT] = {FILLER_REF(sys_getrlimit_setrlrimit)},
	[NODE_SYSCALL_PRLIMIT] = {FILLER_REF(sys_prlimit)},
	[NODE_SYSCALL_FCNTL] = {FILLER_REF(sys_fcntl), 1, APT_REG, {{AF_ID_RETVAL}}},
	[NODE_SYSCALL_BRK_4] = {FILLER_REF(sys_brk_munmap_mmap), 1, APT_REG, {{0}}},
	[NODE_SYSCALL_MMAP] = {FILLER_REF(sys_brk_munmap_mmap)},
	[NODE_SYSCALL_MMAP2] = {FILLER_REF(sys_brk_munmap_mmap)},
	[NODE_SYSCALL_MUNMAP] = {FILLER_REF(sys_brk_munmap_mmap), 2, APT_REG, { {0}, {1} } },
	[NODE_SYSCALL_SPLICE] = {FILLER_REF(sys_empty), 5, APT_REG, { {0}, {2}, {4}, {5}, {AF_ID_RETVAL} } },
	[NODE_SYSCALL_PTRACE] = {FILLER_REF(sys_ptrace)},
	[NODE_SYSCALL_IOCTL_3] = {FILLER_REF(sys_empty), 4, APT_REG, { {0}, {1}, {2}, {AF_ID_RETVAL} } },
	[NODE_SYSCALL_RENAME] = {FILLER_REF(sys_empty), 3, APT_REG, {{AF_ID_RETVAL}, {0}, {1} } },
	[NODE_SYSCALL_RENAMEAT] = {FILLER_REF(sys_renameat)},
	[NODE_SYSCALL_SYMLINK] = {FILLER_REF(sys_empty), 3, APT_REG, {{AF_ID_RETVAL}, {0}, {1} } },
	[NODE_SYSCALL_SYMLINKAT] = {FILLER_REF(sys_symlinkat)},
	[NODE_SYSCALL_SENDFILE] = {FILLER_REF(sys_sendfile)},
	[NODE_SYSCALL_QUOTACTL] = {FILLER_REF(sys_quotactl)},
	[NODE_SYSCALL_SETRESUID] = {FILLER_REF(sys_empty), 4, APT_REG, { {0}, {1}, {2}, {AF_ID_RETVAL} } },
	[NODE_SYSCALL_SETRESGID] = {FILLER_REF(sys_empty), 4, APT_REG, { {0}, {1}, {2}, {AF_ID_RETVAL} } },
	[NODE_SYSCALL_SETUID] = {FILLER_REF(sys_empty), 2, APT_REG, { {0}, {AF_ID_RETVAL} } },
	[NODE_SYSCALL_SETGID] = {FILLER_REF(sys_empty), 2, APT_REG, { {0}, {AF_ID_RETVAL} } },
	[NODE_SYSCALL_GETUID] = {FILLER_REF(sys_empty), 1, APT_REG, {{AF_ID_RETVAL} } },
	[NODE_SYSCALL_GETEUID] = {FILLER_REF(sys_empty), 1, APT_REG, {{AF_ID_RETVAL} } },
	[NODE_SYSCALL_GETGID] = {FILLER_REF(sys_empty), 1, APT_REG, {{AF_ID_RETVAL} } },
	[NODE_SYSCALL_GETEGID] = {FILLER_REF(sys_empty), 1, APT_REG, {{AF_ID_RETVAL} } },
	[NODE_SYSCALL_GETRESUID] = {FILLER_REF(sys_getresuid_and_gid)},
	[NODE_SYSCALL_GETRESGID] = {FILLER_REF(sys_getresuid_and_gid)},
	[NODE_SYSCALL_CLONE_20] = {FILLER_REF(proc_startupdate)},
	[NODE_SYSCALL_FORK_20] = {FILLER_REF(proc_startupdate)},
	[NODE_SYSCALL_VFORK_20] = {FILLER_REF(proc_startupdate)},
	[NODE_SYSCALL_GETDENTS] = {FILLER_REF(sys_empty), 2, APT_REG, {{0}, {AF_ID_RETVAL}}},
	[NODE_SYSCALL_GETDENTS64] = {FILLER_REF(sys_empty), 2, APT_REG, {{0}, {AF_ID_RETVAL}}},
	[NODE_SYSCALL_SETNS] = {FILLER_REF(sys_setns), 1, APT_REG, {{AF_ID_RETVAL}}},
	[NODE_SYSCALL_FLOCK] = {FILLER_REF(sys_flock), 1, APT_REG, {{AF_ID_RETVAL}}},
	[NODE_SOCKET_ACCEPT_5] = {FILLER_REF(sys_accept)},
	[NODE_SOCKET_ACCEPT4_5] = {FILLER_REF(sys_accept4)},
	[NODE_SYSCALL_SEMOP] = {FILLER_REF(sys_semop), 1, APT_REG, {{0}}},
	[NODE_SYSCALL_SEMCTL] = {FILLER_REF(sys_semctl), 1, APT_REG, {{AF_ID_RETVAL}}},
	[NODE_SYSCALL_PPOLL] = {FILLER_REF(sys_ppoll)},
	[NODE_SYSCALL_MOUNT] = {FILLER_REF(sys_mount), 4, APT_REG, {{AF_ID_RETVAL}, {0}, {1}, {2}}},
	[NODE_SYSCALL_UMOUNT] = {FILLER_REF(sys_empty), 3, APT_REG, {{1}, {AF_ID_RETVAL}, {0}}},
	[NODE_SYSCALL_SEMGET] = {FILLER_REF(sys_semget), 1, APT_REG, {{AF_ID_RETVAL}}},
	[NODE_SYSCALL_ACCESS] = {FILLER_REF(sys_access), 2, APT_REG, {{AF_ID_RETVAL}, {0}}},
	[NODE_SYSCALL_CHROOT] = {FILLER_REF(sys_empty), 2, APT_REG, {{AF_ID_RETVAL}, {0}}},
	[NODE_SYSCALL_SETSID] = {FILLER_REF(sys_empty), 1, APT_REG, {{AF_ID_RETVAL}}},
	[NODE_SYSCALL_SETPGID] = {FILLER_REF(sys_empty), 3, APT_REG, {{0}, {1}, {AF_ID_RETVAL}}},
	[NODE_SYSCALL_MKDIR_2] = {FILLER_REF(sys_empty), 3, APT_REG, {{AF_ID_USEDEFAULT, 0}, {AF_ID_RETVAL}, {0}}},
	[NODE_SYSCALL_RMDIR_2] = {FILLER_REF(sys_empty), 2, APT_REG, {{AF_ID_RETVAL}, {0}}},
	[NODE_SYSCALL_UNSHARE] = {FILLER_REF(sys_unshare), 1, APT_REG, {{AF_ID_RETVAL}}},
	[NODE_SYSCALL_EXECVE_19] = {FILLER_REF(sys_execve)},
	[NODE_SYSCALL_BPF] = {FILLER_REF(sys_bpf), 1, APT_REG, {{0}}},
	[NODE_SYSCALL_SECCOMP] = {FILLER_REF(sys_empty), 3, APT_REG, {{0}, {1}, {AF_ID_RETVAL}}},
	[NODE_SYSCALL_UNLINK_2] = {FILLER_REF(sys_empty), 2, APT_REG, {{AF_ID_RETVAL}, {0}}},
	[NODE_SYSCALL_UNLINKAT_2] = {FILLER_REF(sys_unlinkat)},
	[NODE_SYSCALL_MKDIRAT] = {FILLER_REF(sys_mkdirat)},
	[NODE_SYSCALL_OPENAT_2] = {FILLER_REF(sys_openat)},
	[NODE_SYSCALL_LINK_2] = {FILLER_REF(sys_empty), 3, APT_REG, {{AF_ID_RETVAL}, {0}, {1}}},
	[NODE_SYSCALL_LINKAT_2] = {FILLER_REF(sys_linkat)},
	[NODE_SYSCALL_FCHMODAT] = {FILLER_REF(sys_fchmodat)},
	[NODE_SYSCALL_CHMOD] = {FILLER_REF(sys_chmod)},
	[NODE_SYSCALL_FCHMOD] = {FILLER_REF(sys_fchmod)},
	[NODE_SYSCALL_RENAMEAT2] = {FILLER_REF(sys_renameat2)},
	[NODE_SYSCALL_USERFAULTFD] = {FILLER_REF(sys_empty), 2, APT_REG, {{AF_ID_RETVAL}, {0}}},
	[NODE_SYSCALL_OPENAT2] = {FILLER_REF(sys_openat2)},
	[NODE_SYSCALL_MPROTECT] = {FILLER_REF(sys_mprotect)}, 
	[NODE_SYSCALL_EXECVEAT] = {FILLER_REF(sys_execveat)},
	[NODE_SYSCALL_COPY_FILE_RANGE] = {FILLER_REF(sys_copy_file_range)},
	[NODE_SYSCALL_CLONE3] = {FILLER_REF(proc_startupdate)},
};